package com.wjc.wjc.service;

import com.wjc.wjc.dao.RecordRepository;
import com.wjc.wjc.unity.Record;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
public class RecordServiceImpl implements RecordService {

    @Autowired
    private RecordRepository recordRepository;

    @Transactional
    @Override
    public Record save(Record record) {
        return recordRepository.save(record);
    }

    @Override
    public List<Record> lsitRecord() {
        Sort.Order order=new Sort.Order(Sort.Direction.DESC, "id");
        return recordRepository.findAll(Sort.by(order));
    }

    @Override
    public List<Record> lsitReOp() {
        return recordRepository.findByOpinion(false);
    }

    @Override
    public List<Record> lsitRecord(String name) {
        return recordRepository.findAllByName(name);
    }

    @Override
    public List<Record> lsitRecord(boolean opinion) {
        return recordRepository.findByOpinion(opinion);
    }

    @Transactional
    @Override
    public void updataOp(Long id) {
        recordRepository.updataOp(id);
    }


    @Transactional
    @Override
    public void delete(Long id) {
        recordRepository.deleteById(id);
    }

    @Override
    public void updataRemarks(Long id, String remarks) {
        recordRepository.updataRemarks(id, remarks);
    }
}
